<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="record-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">物流公司</label>
        <div class="layui-input-block">
            <select name="expressCompanyCode" lay-search lay-filter="expressCompanyCode" lay-reqtext="物流公司不能为空">
                <option value="">请选择物流公司</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">物流单号</label>
        <div class="layui-input-block">
            <input type="text" name="courierNumber" placeholder="请填写物流单号" lay-reqtext="物流单号不能为空" value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">提交</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/common/commonApi.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>

    let groupBuyingSub;// 订单详情
    let recordId;// 订单记录id

    window.onload = function () {
        recordId = GetQueryString("recordId");

        if (isNotNull(recordId)) {
            // 初始化快递公司列表
            initExpressCompanyList()
            init(recordId);
        } else {
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        }
    }

    /**
     * 初始化数据
     */
    function init(recordId) {
        $.ajax({
            type: "get",
            url: '/buying/get/' + recordId,
            dataType: 'json',
            contentType: 'application/x-www-form-urlencoded',
            success: function (req) {
                groupBuyingSub = req.data;
                layui.use(['form'], function () {
                    let form = layui.form,
                        $ = layui.$;
                    form.val('record-form', {
                        "expressCompanyCode": req.data.expressCompanyCode,
                        "courierNumber": req.data.courierNumber,
                    });
                })
            },
            error: function (e) {
                layer.msg("数据有误");
            }
        })
    }

    layui.use(['layer', 'form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        // 监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("确定提交吗？", {
                title: '提示'
            }, function () {
                let myMsg = layer.msg("正在提交...", {
                    icon: 16,
                    time: -1
                })
                data.field.id = recordId;
                data.field.logisticsModule = 'GROUPBUY';
                $.ajax({
                    type: "post",
                    url: '/express/query/logistics/change',
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json; charset=UTF-8',
                    success: function (req) {
                        layer.msg(req.msg);
                        layer.close(index);
                        // 关闭弹出层
                        setTimeout(function () {
                            layer.close(myMsg);//手动关闭
                            let iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }, 1500);
                    },
                    error: function (e) {
                        layer.msg(e.msg);
                        layer.close(myMsg);//手动关闭
                    }
                })

            });

            return false;
        });

    });

    /**
     * 获取当前时间并格式化为yyyy-MM-dd HH:mm:ss函数
     * @return 得到类似 2021-06-23 12:07:33 的值
     */
    function _getTimes() {
        const thisDay = new Date();
        const year = thisDay.getFullYear();       //年
        const month = thisDay.getMonth() + 1;     //月
        const day = thisDay.getDate();            //日
        const hh = thisDay.getHours();            //时
        const mm = thisDay.getMinutes();          //分
        const ss = thisDay.getSeconds();          //秒
        let timer = year + "-";
        if (month < 10)
            timer += "0";
        timer += month + "-";
        if (day < 10)
            timer += "0";
        timer += day + " ";
        if (hh < 10)
            timer += "0";
        timer += hh + ":";
        if (mm < 10)
            timer += '0';
        timer += mm + ":";
        if (ss < 10)
            timer += '0';
        timer += ss;
        return (timer);
    }

</script>

</body>
</html>